package cn.z2huo.knowledge.concurrency.thinkinginjava.section_21_3.syncCodeBlock;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 非线程安全的
 */
@Getter
@Setter
@ToString
class Pair {

    private int x;

    private int y;

    public Pair() {
        this(0, 0);
    }

    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public void incrementX() {
        x++;
    }

    public void incrementY() {
        y++;
    }

    /**
     * 判断两个变量是否相等
     */
    public void checkState() {
        if (x != y) {
            throw new PairValuesNotEqualException(this);
        }
    }

}
